/**
 * Created by Administrator on 2017/3/30 0030.
 */
var PageSee={
    create: function () {
        var page={}
        page.ui=new PIXI.DisplayObjectContainer();
        var bg=new PIXI.Graphics();
        bg.beginFill(0x0,1);
        bg.drawRect(0,0,740,1136);
        bg.endFill();
        //page.ui.addChild(bg);

        //var sp_bg=new PIXI.Sprite(resource['assets/images/pSee_bg.png'].texture);
        //sp_bg.anchor.set(0.0);
        //sp_bg.x = 0;
        //sp_bg.y = 0;
        //page.ui.addChild(sp_bg);

        var i0=new PIXI.Sprite(resource['assets/images/pSee_i0.png'].texture);
        i0.anchor.set(0.5);
        page.ui.addChild(i0);
        i0.x=369;
        i0.y=574;

        var i1=new PIXI.Sprite(resource['assets/images/pSee_i1.png'].texture);
        i1.anchor.set(0.5);
        page.ui.addChild(i1);
        i1.x=369;
        i1.y=574;

        var i2=new PIXI.Sprite(resource['assets/images/pSee_i2.png'].texture);
        i2.anchor.set(0.5);
        page.ui.addChild(i2);
        i2.x=369;
        i2.y=574;

        var line=new PIXI.Graphics();
        line.beginFill(0xffffff,1);
        line.drawRect(-200/2,-2/2,200,2);
        line.endFill();
        line.x=363;
        line.y=576;
        line.scale.x=0;
        line.scale.y=1;
        page.ui.addChild(line);

        var t0=new PIXI.Sprite(resource['assets/images/pSee_t0.png'].texture);
        t0.anchor.set(0.5);
        page.ui.addChild(t0);
        t0.x=243;
        t0.y=578;
        var mask_0=new PIXI.Graphics();
        mask_0.beginFill(0,1);
        mask_0.drawCircle(0,0,182);
        mask_0.endFill();
        mask_0.x=t0.x;
        mask_0.y=t0.y;
        mask_0.scale.x=mask_0.scale.y=0;
        page.ui.addChild(mask_0);
        t0.mask=mask_0;

        var t1=new PIXI.Sprite(resource['assets/images/pSee_t1.png'].texture);
        t1.anchor.set(0.5);
        page.ui.addChild(t1);
        t1.x=363;
        t1.y=578;
        var mask_1=new PIXI.Graphics();
        mask_1.beginFill(0,1);
        mask_1.drawCircle(0,0,182);
        mask_1.endFill();
        mask_1.x=t1.x;
        mask_1.y=t1.y;
        mask_1.scale.x=mask_1.scale.y=0;
        page.ui.addChild(mask_1);
        t1.mask=mask_1;

        var t2=new PIXI.Sprite(resource['assets/images/pSee_t2.png'].texture);
        t2.anchor.set(0.5);
        page.ui.addChild(t2);
        t2.x=488;
        t2.y=578;
        var mask_2=new PIXI.Graphics();
        mask_2.beginFill(0,1);
        mask_2.drawCircle(0,0,182);
        mask_2.endFill();
        mask_2.x=t2.x;
        mask_2.y=t2.y;
        mask_2.scale.x=mask_2.scale.y=0;
        page.ui.addChild(mask_2);
        t2.mask=mask_2;

        var t3=new PIXI.Sprite(resource['assets/images/pSee_t3.png'].texture);
        t3.anchor.set(0.5);
        page.ui.addChild(t3);
        t3.x=363;
        t3.y=576;
        t3.alpha=0;
        page.ui.addChild(t3);


        page.In=function()
        {
            //t2.mask=
            t0.scale.x=t0.scale.y=2.5;
            mask_0.scale.x=mask_0.scale.y=0;
            TweenMax.to(t0.scale,1.5,{delay:1+0.5*0,x:1,y:1,ease:Cubic.easeOut});
            TweenMax.to(mask_0.scale,1.5,{delay:1+0.5*0,x:1,y:1,ease:Back.easeOut});

            t1.scale.x=t1.scale.y=2.5;
            mask_1.scale.x=mask_1.scale.y=0;
            TweenMax.to(t1.scale,1.5,{delay:1+0.5*1,x:1,y:1,ease:Cubic.easeOut});
            TweenMax.to(mask_1.scale,1.5,{delay:1+0.5*1,x:1,y:1,ease:Back.easeOut});

            t2.scale.x=t2.scale.y=2.5;
            mask_2.scale.x=mask_2.scale.y=0;
            TweenMax.to(t2.scale,1.5,{delay:1+0.5*2,x:1,y:1,ease:Cubic.easeOut});
            TweenMax.to(mask_2.scale,1.5,{delay:1+0.5*2,x:1,y:1,ease:Back.easeOut});

            TweenMax.to(line.scale,1.5,{delay:2+0.5*4,x:1,ease:Back.easeOut});

            setTimeout(function()
            {
                createCircle();
                TweenMax.to(t3,1,{alpha:1});
            },3000)


            i0.scale.x=i0.scale.y=i0.alpha=0;
            i1.scale.x=i1.scale.y=i1.alpha=0;
            i2.scale.x=i2.scale.y=i2.alpha=0;
            i0.rotation=-Math.PI*2;
            i1.rotation=Math.PI*1;
            i2.rotation=Math.PI/2;
            TweenMax.to(i0,1.5,{delay:1.5+2.5,alpha:1,rotation:0,ease:Back.easeOut});
            TweenMax.to(i0.scale,1.5,{delay:1.5+2.5,  x:1,y:1,ease:Back.easeOut,onComplete:function()
            {
                TweenMax.to(i0,5,{rotation:Math.PI*2,repeat:-1,ease:Linear.easeNone});
            }});

            TweenMax.to(i1,1.5,{delay:1.5+2.7,alpha:1,rotation:0,ease:Back.easeOut});
            TweenMax.to(i1.scale,1.5,{delay:1.5+2.7,x:1,y:1,ease:Back.easeOut,onComplete:function()
            {
                TweenMax.to(i1,10,{rotation:-Math.PI*2,repeat:-1,ease:Linear.easeNone});
            }});

            TweenMax.to(i2,1.5,{delay:1.5+3.4,alpha:1,rotation:0,ease:Back.easeOut});
            TweenMax.to(i2.scale,1.5,{delay:1.5+2.9,x:1,y:1,ease:Back.easeOut,onComplete:function()
            {
                TweenMax.to(i2,15,{rotation:Math.PI*2,repeat:-1,ease:Linear.easeNone});
            }});

            setTimeout(function()
            {
                TweenMax.to(t0,1,{delay:0,alpha:0,y:t0.y+160,ease:Back.easeIn});
                TweenMax.to(t1,1,{delay:0.0,alpha:0,y:t1.y-160,ease:Back.easeIn});
                TweenMax.to(t2,1,{delay:0.0,alpha:0,y:t2.y+160,ease:Back.easeIn});

                TweenMax.to(t3,1,{delay:0,alpha:0});
                TweenMax.to(t3.scale,1,{delay:0,x:3,y:3,ease:Back.easeIn});
                TweenMax.to(line,1,{delay:0.3,alpha:0,ease:Cubic.Out});
                TweenMax.to(line.scale,1,{delay:0.3,x:0,y:0,ease:Cubic.Out});


                TweenMax.to(i0,1,{delay:0.8,alpha:0,ease:Back.easeIn});
                TweenMax.to(i0.scale,1,{delay:0.8,x:4,y:4,ease:Back.easeIn});

                TweenMax.to(i1,1,{delay:0.9,alpha:0,ease:Back.easeIn});
                TweenMax.to(i1.scale,1,{delay:0.9,x:4,y:4,ease:Back.easeIn});

                TweenMax.to(i2,1,{delay:1.0,alpha:0,ease:Back.easeIn});
                TweenMax.to(i2.scale,1,{delay:1.0,x:4,y:4,ease:Back.easeIn});

                threeOut();

                //以下逻辑写在threeOut里
                // setTimeout(function () {
                //     var evt=new CustomEvent('Game_PageIn',{detail:'mc'})
                //     document.dispatchEvent(evt);
                // },3000)
            },8000);
        }

        function createCircle()
        {
            for(var i=0;i<20;i++)
            {
                var circle=Circle.create(0,0,0x877B5F);
                page.ui.addChild(circle.ui);

                circle.ui.x=369;
                circle.ui.y=575;

                //arr_circle.push(circle);

                circle.ui.scale.x=0;
                circle.ui.scale.y=0;
                TweenMax.to(circle.ui,1.25,{delay:0.1*i,alpha:0});
                TweenMax.to(circle.ui.scale,1.25,{delay:0.05*i,x:1-i*0.01,y:1-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
                    c.ui.parent.removeChild(c.ui);
                    c=null;
                    //arr_circle.splice(arr_circle.indexOf(c),1);
                    //console.log(arr_circle.length);
                }});

            }
        }


        return page;
    }
}